<<<<<<< HEAD
/*
 * @Author: your name
 * @Date: 2020-05-24 19:06:23
 * @LastEditTime: 2020-05-27 22:50:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \InformationVisualization-COVID19\static\echarts\map.js
 */
function map() {
  //geoCoordMap 用于给地图上的城市显示的经纬度坐标(资源文件)
  /*数据格式：对象 键值对  
      '上海': [121.4648,31.2891],
  */
  var geoCoordMap = {
    "江西": [116.0046, 28.6633],
    '上海': [121.4648, 31.2891],
    '东莞': [113.8953, 22.901],
    '东营': [118.7073, 37.5513],
    '中山': [113.4229, 22.478],
    '临汾': [111.4783, 36.1615],
    '临沂': [118.3118, 35.2936],
    '丹东': [124.541, 40.4242],
    '丽水': [119.5642, 28.1854],
    '新疆': [86.9236, 41.5883],
    '佛山': [112.8955, 23.1097],
    '保定': [115.0488, 39.0948],
    '甘肃': [103.9901, 36.3043],
    '北京': [116.4551, 40.4539],
    '北海': [109.314, 21.6211],
    '江苏': [120.2062, 32.9208],
    '广西': [108.479, 24.1152],
    '南通': [121.1023, 32.1625],
    '厦门': [118.1689, 24.6478],
    '台州': [121.1353, 28.6688],
    '安徽': [117.29, 32.0581],
    '内蒙古': [111.4124, 41.4901],
    '咸阳': [108.4131, 34.8706],
    '黑龙江': [127.9688, 46.868],
    '唐山': [118.4766, 39.6826],
    '嘉兴': [120.9155, 30.6354],
    '大同': [113.7854, 39.8035],
    '天津': [117.4219, 39.4189],
    '山西': [112.3352, 37.9413],
    '威海': [121.9482, 37.1393],
    '宁波': [121.5967, 29.6466],
    '宝鸡': [107.1826, 34.3433],
    '宿迁': [118.5535, 33.7775],
    '广东': [114.5107, 23.8196],
    '廊坊': [116.521, 39.0509],
    '延安': [109.1052, 36.4252],
    '张家口': [115.1477, 40.8527],
    '徐州': [117.5208, 34.3268],
    '德州': [116.6858, 37.2107],
    '惠州': [114.6204, 23.1647],
    '四川': [103.9526, 30.7617],
    '扬州': [119.4653, 32.8162],
    '承德': [117.5757, 41.4075],
    '西藏': [91.1865, 30.1465],
    '无锡': [120.3442, 31.5527],
    '日照': [119.2786, 35.5023],
    '云南': [101.9199, 25.0663],
    '浙江': [119.5313, 29.8773],
    '枣庄': [117.323, 34.8926],
    '柳州': [109.3799, 24.9774],
    '株洲': [113.5327, 27.0319],
    '湖北': [113.0896, 31.3628],
    '汕头': [117.1692, 23.3405],
    '江门': [112.6318, 22.1484],
    '辽宁': [123.1238, 42.1216],
    '沧州': [116.8286, 38.2104],
    '河源': [114.917, 23.9722],
    '泉州': [118.3228, 25.1147],
    '泰安': [117.0264, 36.0516],
    '泰州': [120.0586, 32.5525],
    '山东': [117.1582, 36.8701],
    '济宁': [116.8286, 35.3375],
    '海口': [110.3893, 19.8516],
    '淄博': [118.0371, 36.6064],
    '淮安': [118.927, 33.4039],
    '深圳': [114.5435, 22.5439],
    '清远': [112.9175, 24.3292],
    '温州': [120.498, 27.8119],
    '渭南': [109.7864, 35.0299],
    '湖州': [119.8608, 30.7782],
    '湘潭': [112.5439, 27.7075],
    '滨州': [117.8174, 37.4963],
    '潍坊': [119.0918, 36.524],
    '烟台': [120.7397, 37.5128],
    '玉溪': [101.9312, 23.8898],
    '珠海': [113.7305, 22.1155],
    '盐城': [120.2234, 33.5577],
    '盘锦': [121.9482, 41.0449],
    '河北': [115.4995, 38.6006],
    '福建': [118.0543, 26.5222],
    '秦皇岛': [119.2126, 40.0232],
    '绍兴': [120.564, 29.7565],
    '聊城': [115.9167, 36.4032],
    '肇庆': [112.1265, 23.5822],
    '舟山': [122.2559, 30.2234],
    '苏州': [120.6519, 31.3989],
    '莱芜': [117.6526, 36.2714],
    '菏泽': [115.6201, 35.2057],
    '营口': [122.4316, 40.4297],
    '葫芦岛': [120.1575, 40.578],
    '衡水': [115.8838, 37.7161],
    '衢州': [118.6853, 28.8666],
    '青海': [97.4038, 35.8207],
    '陕西': [109.1162, 34.2004],
    '贵州': [106.6992, 26.7682],
    '连云港': [119.1248, 34.552],
    '邢台': [114.8071, 37.2821],
    '邯郸': [114.4775, 36.535],
    '河南': [113.4668, 34.6234],
    '鄂尔多斯': [108.9734, 39.2487],
    '重庆': [107.7539, 30.1904],
    '金华': [120.0037, 29.1028],
    '铜川': [109.0393, 35.1947],
    '宁夏': [106.3586, 38.1775],
    '镇江': [119.4763, 31.9702],
    '吉林': [125.8154, 44.2584],
    '湖南': [111.8823, 28.2568],
    '长治': [112.8625, 36.4746],
    '阳泉': [113.4778, 38.0951],
    '青岛': [120.4651, 36.3373],
    '韶关': [113.7964, 24.7028],
    '海南': [109.8500, 19.7028],
    '台湾': [120.7964, 24.1528],
    '澳门': [110.3500, 22.2000],
    '香港': [114.10000, 22.20000],
    '兰州': [103.5901, 36.3043],
    '包头': [110.3467, 41.4899],
    '南京': [118.8062, 31.9208],
    '南宁': [108.479, 23.1152],
    '南昌': [116.0046, 28.6633],
    '合肥': [117.29, 32.0581],
    '呼和浩特': [111.4124, 40.4901],
    '哈尔滨': [127.9688, 45.368],
    '大连': [122.2229, 39.4409],
    '太原': [112.3352, 37.9413],
    '常州': [119.4543, 31.5582],
    '广州': [113.5107, 23.2196],
    '成都': [103.9526, 30.7617],
    '拉萨': [91.1865, 30.1465],
    '昆明': [102.9199, 25.4663],
    '杭州': [119.5313, 29.8773],
    '武汉': [114.3896, 30.6628],
    '沈阳': [123.1238, 42.1216],
    '济南': [117.1582, 36.8701],
    '石家庄': [114.4995, 38.1006],
    '福州': [119.4543, 25.9222],
    '西宁': [101.4038, 36.8207],
    '西安': [109.1162, 34.2004],
    '贵阳': [106.6992, 26.7682],
    '郑州': [113.4668, 34.6234],
    '银川': [106.3586, 38.1775],
    '长春': [125.8154, 44.2584],
    '长沙': [113.0823, 28.2568],


  };
  //这是北京到各个城市的数据  前面是出发地,后面是到达地 value是相关权值
  /*数据格式  
  [{name:'北京'}, {name:'上海',value:95}],
  */
  var BJData = [
    [{ name: '湖北' }, { name: '新疆', value: 76 }],
    [{ name: '湖北' }, { name: '西藏', value: 1 }],
    [{ name: '湖北' }, { name: '青海', value: 18 }],
    [{ name: '湖北' }, { name: '甘肃', value: 139 }],
    [{ name: '湖北' }, { name: '内蒙古', value: 232 }],
    [{ name: '湖北' }, { name: '宁夏', value: 75 }],
    [{ name: '湖北' }, { name: '陕西', value: 308 }],
    [{ name: '湖北' }, { name: '四川', value: 564 }],
    [{ name: '湖北' }, { name: '云南', value: 185 }],
    [{ name: '湖北' }, { name: '重庆', value: 579 }],
    [{ name: '湖北' }, { name: '广东', value: 1592 }],
    [{ name: '湖北' }, { name: '贵州', value: 147 }],
    [{ name: '湖北' }, { name: '广西', value: 254 }],
    [{ name: '湖北' }, { name: '海南', value: 169 }],
    [{ name: '湖北' }, { name: '湖北', value: (68135 / 10) }],
    [{ name: '湖北' }, { name: '湖南', value: 1019 }],
    [{ name: '湖北' }, { name: '山西', value: 198 }],
    [{ name: '湖北' }, { name: '河南', value: 1276 }],
    [{ name: '湖北' }, { name: '河北', value: 328 }],
    [{ name: '湖北' }, { name: '黑龙江', value: 945 }],
    [{ name: '湖北' }, { name: '吉林', value: 155 }],
    [{ name: '湖北' }, { name: '辽宁', value: 149 }],
    [{ name: '湖北' }, { name: '北京', value: 593 }],
    [{ name: '湖北' }, { name: '天津', value: 192 }],
    [{ name: '湖北' }, { name: '山东', value: 788 }],
    [{ name: '湖北' }, { name: '安徽', value: 991 }],
    [{ name: '湖北' }, { name: '福建', value: 357 }],
    [{ name: '湖北' }, { name: '重庆', value: 579 }],
    [{ name: '湖北' }, { name: '江西', value: 937 }],
    [{ name: '湖北' }, { name: '澳门', value: 45 }],
    [{ name: '湖北' }, { name: '香港', value: 1065 }],
    [{ name: '湖北' }, { name: '江苏', value: 653 }],
    [{ name: '湖北' }, { name: '浙江', value: 1268 }],
    [{ name: '湖北' }, { name: '上海', value: 669 }],
    [{ name: '湖北' }, { name: '台湾', value: 441 }]
  ];
  //模拟出发城市到各大目的地对应的路线路图（就是图上的小飞机路线）用的是svg画的矢量图
  var planePath = 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z';
  //用于转换成我们需要的格式的数据
  /*
  [
      [{coord:fromCoord},{coord:toCoord}]
      其中fromCoord和toCoord都是经纬度
  ]
  */
  var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
      var dataItem = data[i];
      var fromCoord = geoCoordMap[dataItem[0].name];
      var toCoord = geoCoordMap[dataItem[1].name];
      if (fromCoord && toCoord) {
        res.push([{
          coord: fromCoord
        }, {
          coord: toCoord
        }]);
      }
    }
    return res;
  };
  //填充planePath（svg图形）的颜色 分别对应北京 上海 广州
  var color = ['#a6c84c', '#ffa022', '#46bee9'];
  //图表的系列内容配置填充
  var series = [];
  [['北京', BJData]].forEach(function (item, i) {
    series.push({
      name: item[0] + ' Top10',//系列的名称
      type: 'lines',//用于带有起点和终点信息的绘制，主要用于地图上的航线，路线可视化
      zlevel: 1,//用于canavs分层，大的放上边
      //线的特效
      effect: {
        show: true,
        period: 6, //特效动画的时间 单位ss
        trailLength: 0.7,//特效尾迹的长度
        color: '#fff',
        symbolSize: 3//特效标记的大小
      },
      //线的样式
      lineStyle: {
        normal: {
          color: color[i],
          width: 0,
          curveness: 0.2 //边的曲度
        }
      },
      //我们需要的数据
      data: convertData(item[1])
    },
      {
        name: item[0] + ' Top10',
        type: 'lines',
        zlevel: 2,
        effect: {
          show: true,
          period: 6,
          trailLength: 0,
          symbol: planePath,//线的形式(这里是小飞机)
          symbolSize: 15//大小
        },
        lineStyle: {
          normal: {
            color: color[i],
            width: 1,
            opacity: 0.4,//透明度
            curveness: 0.2
          }
        },
        data: convertData(item[1])
      },
      {
        name: item[0] + ' Top10',
        type: 'effectScatter',//效果分散
        coordinateSystem: 'geo',//该系列使用的坐标系
        zlevel: 2,
        rippleEffect: {
          brushType: 'stroke'//波纹的绘制方式  
        },
        //标签
        label: {
          normal: {
            show: true,
            position: 'right',
            formatter: '{b}'
          }
        },
        //符号大小（这里指effectScatter）
        symbolSize: function (val) {//这里的value是我们绑定的数据
          return val[2] / 80;
        },
        itemStyle: {
          normal: {
            color: color[i]
          }
        },
        /*数据格式 
        {name: "上海"
        value: (3) [121.4648, 31.2891, 95]}
        */
        data: item[1].map(function (dataItem) {
          var temp = {
            name: dataItem[1].name,
            //concat用于连接两个数组
            value: geoCoordMap[dataItem[1].name].concat([dataItem[1].value])
          };
          console.log(dataItem[1].name);
          console.log(temp);
          console.log(typeof temp);
          return temp;
        })
      }
    );
  });
  var mycharts = echarts.init(document.getElementById('map'), 'macarons2');
  //选项配置
  option = {
    backgroundColor: '#404a59',//背景颜色 注意不是地图的颜色 是背景的颜色
    //标题
    title: {
      text: '模拟迁徙',
      subtext: '数据纯属虚构',
      left: 'center',
      textStyle: {//标题样式
        color: '#fff'
      }
    },
    //提示工具
    tooltip: {
      trigger: 'item',//触发方式：点
      formatter: function (params, ticket, callback) {
        if (params.seriesType == "effectScatter") {
          if (params.data.name == '湖北') {
            return params.data.name + ": " + params.data.value[2] * 10 + '人';
          }
          return params.data.name + ": " + params.data.value[2] + '人';
        }
      }
    },
    //图例 可以用来切换 北上广的按钮
    legend: {
      orient: 'vertical',
      top: 'bottom',
      left: 'right',
      //图例的data用于切换系列 所以要与系列的name保持一致
      data: ['全国确诊情况'],
      textStyle: {
        color: '#fff'
      },
      //选中模式 单个 意思是图上每次只能显示单个系列
      selectedMode: 'single'
    },
    //设置中国地图
    geo: {
      map: 'china',
      //这里的label是标签 也就是地图上的城市名字（基于我们的geoCoordMap数据）
      label: {
        emphasis: {
          show: false
        }
      },
      //地图漫游 就是缩放的意思
      roam: true,
      //区域颜色
      itemStyle: {
        //正常时
        normal: {
          areaColor: '#323c48',
          borderColor: '#404a59'
        },
        //触发时（就是鼠标移入时）
        emphasis: {
          areaColor: '#2a333d'
        }
      }
    },
    series: series
  };
  mycharts.setOption(option);
}




=======
function map() {
    var mycharts = echarts.init(document.getElementById('map'));
    var geoCoordMap = {
        '新疆': [86.61, 40.79],
        '西藏': [89.13, 30.66],
        '黑龙江': [128.34, 47.05],
        '吉林': [126.32, 43.38],
        '辽宁': [123.42, 41.29],
        '内蒙古': [112.17, 42.81],
        '北京': [116.40, 40.40],
        '宁夏': [106.27, 36.76],
        '山西': [111.95, 37.65],
        '河北': [115.21, 38.44],
        '天津': [117.04, 39.52],
        '青海': [97.07, 35.62],
        '甘肃': [103.82, 36.05],
        '山东': [118.01, 36.37],
        '陕西': [108.94, 34.46],
        '河南': [113.46, 34.25],
        '安徽': [117.28, 31.86],
        '江苏': [120.26, 32.54],
        '上海': [121.46, 31.28],
        '四川': [103.36, 30.65],
        '湖北': [112.29, 30.98],
        '浙江': [120.15, 29.28],
        '重庆': [107.51, 29.63],
        '湖南': [112.08, 27.79],
        '江西': [115.89, 27.97],
        '贵州': [106.91, 26.67],
        '福建': [118.31, 26.07],
        '云南': [101.71, 24.84],
        '台湾': [121.01, 23.54],
        '广西': [108.67, 23.68],
        '广东': [113.98, 22.82],
        '海南': [110.03, 19.33],
        '澳门': [113.54, 22.19],
        '香港': [114.17, 22.32],
    };
    var data = [{
        name: '河北',
        value: 65266
    }, {
        name: '山西',
        value: 61547
    }, {
        name: '辽宁',
        value: 62545
    }, {
        name: '吉林',
        value: 62908
    }, {
        name: '江苏',
        value: 79741
    }, {
        name: '浙江',
        value: 82642
    }, {
        name: '安徽',
        value: 67927
    }, {
        name: '福建',
        value: 69029
    }, {
        name: '江西',
        value: 63069
    }, {
        name: '山东',
        value: 69305
    }, {
        name: '河南',
        value: 55997
    }, {
        name: '湖北',
        value: 67736
    }, {
        name: '湖南',
        value: 65994
    }, {
        name: '广东',
        value: 80020
    }, {
        name: '海南',
        value: 69062
    }, {
        name: '四川',
        value: 71631
    }, {
        name: '贵州',
        value: 75109
    }, {
        name: '云南',
        value: 73515
    }, {
        name: '陕西',
        value: 67433
    }, {
        name: '甘肃',
        value: 65726
    }, {
        name: '青海',
        value: 76535
    }, {
        name: '黑龙江',
        value: 59995
    }, ];
    var convertData = function(data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            }
        }
        return res;
    };
    option = {
        title: {
            text: '2018全国各省平均工资',
            subtext: '数据来源: 国家数据中心',
            left: 'center',
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'item',
            confine: true,
            formatter: (p) => { //自定义提示信息
                let dataCon = p.data;
                txtCon = dataCon.name + '<br>年平均工资:' + dataCon.value[2] + '元';
                return txtCon;
            }
        },
        visualMap: {
            min: 50000, //最小
            max: 90000, //最大
            splitNumber: 4, //共分5层
            color: ['#ff6300', '#eac736', '#50a3ba'], //颜色从高到低依次渐变
            textStyle: {
                color: 'red'
            }
        },
        geo: {
            map: 'china',
            roam: true,
            label: {
                normal: {
                    show: false
                },
                emphasis: {
                    show: false
                }
            },
            itemStyle: {
                //未激活样式
                normal: {
                    areaColor: '#3FA1E2',
                    borderColor: '#3B5077'
                },
                //激活样式
                emphasis: {
                    areaColor: '#22FFFF'
                }
            }
        },
        series: [{
            name: '学生人数',
            type: 'scatter',
            coordinateSystem: 'geo',
            data: convertData(data),
            symbolSize: function(val) {
                return val[2] / 3000;
            },
            label: {
                show: false,
                //		                normal: {
                //		                    show: true
                //		                },
                //		                emphasis: {
                //		                    show: true
                //		                },
                formatter: '{b}',
                offset: [15, -15], //文字的相对偏移
            },
            label: {
                //   show: false,
                normal: {
                    show: false
                },
                emphasis: {
                    show: true
                },
                formatter: '{b}',
                offset: [15, -15], //文字的相对偏移
            },
            itemStyle: {
                emphasis: {
                    borderColor: '#fff',
                    borderWidth: 1
                }
            }
        }, {
            name: 'Top 5',
            type: 'effectScatter',
            coordinateSystem: 'geo',
            data: convertData(data.sort(function(a, b) {
                return b.value - a.value;
            }).slice(0, 6)),
            symbolSize: function(val) {
                return val[2] / 3000;
            },
            showEffectOn: 'render',
            rippleEffect: {
                brushType: 'stroke'
            },
            hoverAnimation: true,
            label: {
                normal: {
                    formatter: '{b}',
                    position: 'right',
                    show: true
                }
            },
            itemStyle: {
                normal: {
                    color: 'purple',
                    shadowBlur: 10,
                    shadowColor: '#333'
                }
            },
            zlevel: 1
        }]
    }
    mycharts.setOption(option);

}
>>>>>>> 812781067fd963b4f19b3245d2d3de87456c9a12
